package com.demo.utils.exception;



import com.demo.utils.error.GlobalErrorEnum;
import lombok.Getter;


/**
 * 业务异常
 *
 * @author system
 */
public final class BizServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;


    /**
     * 适配个别httpcode是非-1
     */
    @Getter
    private Integer httpCode;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 错误明细，内部调试错误
     * <p>
     */
    private String detailMessage;

    /**
     * 空构造方法，避免反序列化问题
     */
    public BizServiceException() {
    }

    public BizServiceException(String message) {
        this.message = message;
    }

    public BizServiceException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public BizServiceException(Integer code, String message) {
        this.message = message;
        this.code = code;
    }

    public BizServiceException(Integer httpCode, Integer code, String message) {
        this.message = message;
        this.code = code;
        this.httpCode = httpCode;
    }

    public BizServiceException(GlobalErrorEnum errorEnum) {
        this.message = errorEnum.getErrorMessage();
        this.code = errorEnum.getErrorCode();
    }



    public BizServiceException(GlobalErrorEnum errorEnum, String message) {
        this.message = message;
        this.code = errorEnum.getErrorCode();
    }

    public String getDetailMessage() {
        return detailMessage;
    }

    public BizServiceException setDetailMessage(String detailMessage) {
        this.detailMessage = detailMessage;
        return this;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public BizServiceException setMessage(String message) {
        this.message = message;
        return this;
    }

    public Integer getCode() {
        return code;
    }

}
